<template>
	<view style="padding-bottom: 30rpx;">
		<project-item v-for="(item,index) in list" :key="index" @fabu='fabu(index)' @del='del(item)' :index='index'
			:ismy="true" :pro="item"></project-item>
		<u-loadmore :status="status" @loadmore="onre"/>

		<image @click="clickto('/pages/project/type')"
			style="width: 147rpx;height: 140rpx;position: fixed;bottom: 40rpx;right: 26rpx;" src="/static/img/fabu.png"
			mode=""></image>

		<u-popup :show="show" @close="show=false" mode="bottom">
			<view v-if="show" :style="{paddingBottom:height+'px'}">
				<view class="textbox">
					<u--textarea autoHeight :disableDefaultPadding='true' :cursor='list[curindex].text.length'
						placeholderStyle='color: #fff' v-model="list[curindex].text" :showConfirmBar='false'
						placeholder="请输入内容" :focus='focus' :adjustPosition='false'></u--textarea>
					<view class="sendbox">
						发送
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		getMyDymicList,
		deleteDymic
	} from '@/api/dymic.js'
	export default {
		data() {
			return {
				keyword: '',
				show: false,
				curindex: null,
				list: [],
				height: 0,
				focus: true,
				status: 'loadmore',
				page: 1,
				last_page:0
			};
		},
		methods: {
			fabu(index) {
				this.show = true
				this.curindex = index
			},
			del(item) {
				console.log('删除', item)
				let _this=this
				uni.showModal({
					title: '提示',
					content: '确定要删除该项目？',
					success(res) {
						// console.log(res)
						if (res.confirm) {
							deleteDymic({
								dymic_id: item.id
							}).then(r => {
								if(r.data.code==1){
									uni.showToast({
										title:'删除成功',
										icon:'none'
									})
									_this.page=1
									_this.list=[]
									_this.getlist()
								}
							})
						}
					}
				})

			},
			clickto(url) {
				uni.navigateTo({
					url
				})
			},
			getlist() {
				getMyDymicList({page:this.page}).then(res => {
					this.status='loadmore'
					this.last_page=res.data.data.last_page
					this.list=[...this.list,...res.data.data.data]
					uni.stopPullDownRefresh()
					this.list.map(t => {
						t.imgs = []
						t.image.split(',').map(r => {
							t.imgs.push(this.$BASE_URL + r)
						})
						t.text = ''
						uni.getStorageSync('xmtypelist').map(n=>{
							if(n.id==t.type){
								t.typename=n.name
							}
						})
					})
				})
			},
			onre(){
				this.page++
				if(this.page<=this.last_page){
					this.getlist()
				}else{
					this.status='nomore'
				}
			}
		},
		onLoad() {
			let _this = this
			uni.onKeyboardHeightChange(res => {
				// console.log(res.height)
				_this.height = res.height
			})
			this.getlist()
		},
		onReachBottom() {
			this.onre()
		},
		onPullDownRefresh() {
			this.page=1
			this.list=[]
			this.getlist()
		}
	}
</script>

<style lang="less">
	.textbox {
		padding: 30rpx;
		display: flex;
		align-items: center;

		.sendbox {
			padding: 0 28rpx;
			line-height: 63rpx;
			background: linear-gradient(265deg, #FF8717, #FF5F00);
			border-radius: 32rpx;
			color: #fff;
			font-size: 28rpx;
			margin-left: 19rpx;
		}
	}

	/dee/.u-textarea {
		background-color: #F9F9F9 !important;
	}

	.fb {
		position: fixed;
		bottom: 159rpx;
		right: 24rpx;
		width: 147rpx;
		height: 140rpx;
	}
</style>
